package com.apkcore.core.util

import android.os.Handler
import android.os.Looper

object UiUtil {
    private val handler by lazy { Handler(Looper.getMainLooper()) }

    fun runOnUiThread(delay: Long = 0, action: Runnable) {
        if (delay > 0) {
            handler.postDelayed(action, delay)
            return
        }
        if (Looper.getMainLooper() == Looper.myLooper()) {
            action.run()
        } else {
            handler.post(action)
        }
    }

    fun release() {
        handler.removeCallbacksAndMessages(null)
    }
}